using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class v_UsersInDepartmentMap : EntityTypeConfiguration<v_UsersInDepartment>
    {
        public v_UsersInDepartmentMap()
        {
            // Primary Key
            this.HasKey(t => new { t.UserId, t.DeparmentId });

            // Properties
            this.Property(t => t.DeparmentId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("v_UsersInDepartment");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.DeparmentId).HasColumnName("DeparmentId");
            this.Property(t => t.PositionId).HasColumnName("PositionId");
            this.Property(t => t.IsActive).HasColumnName("IsActive");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");
            this.Property(t => t.DocReceiver).HasColumnName("DocReceiver");

            // Relationships
            this.HasRequired(t => t.aspnet_Users)
                .WithMany(t => t.v_UsersInDepartment)
                .HasForeignKey(d => d.UserId);
            this.HasRequired(t => t.v_Department)
                .WithMany(t => t.v_UsersInDepartment)
                .HasForeignKey(d => d.DeparmentId);
            this.HasOptional(t => t.v_Position)
                .WithMany(t => t.v_UsersInDepartment)
                .HasForeignKey(d => d.PositionId);

        }
    }
}
